﻿using Main.DataBaseContext;
using Main.dto;
using Microsoft.EntityFrameworkCore;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Data;

namespace Main.Views
{
    /// <summary>
    /// Interaction logic for ToDoTaskView
    /// </summary>
    public partial class ToDoTaskView : UserControl
    {
        private readonly BusnessContext busnessContext;

        public CollectionViewSource ToDoTasks { get; }

        public ToDoTaskView(BusnessContext busnessContext)
        {
            InitializeComponent();

            this.busnessContext = busnessContext;

            ToDoTasks = (CollectionViewSource)FindResource(nameof(ToDoTasks));
        }

        private async void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            await busnessContext.ToDoTasks.LoadAsync();

            ToDoTasks.Source = busnessContext.ToDoTasks.Local.ToObservableCollection();
        }
    }
}
